Skip to content

fix(example-todo): give todo_task a days_overdue formula field so the overdue escalation notice renders its day count - #19205

Merged
huangyiirene merged 4 commits into
mainfrom
claude/issue-18584-days-overdue-formula-field
Sep 19, 2026
Merged

huangyiirene merged 4 commits into
mainfrom
claude/issue-18584-days-overdue-formula-field

Conversation

@huangyiirene

Copy link
Copy Markdown
Collaborator

Fixes #18584

Clause-②: no

The overdue_escalation notification body interpolated {currentTask.days_overdue} while todo_task declared no such field, so the day count rendered as a blank — silently, with no error. This adds the field as a formula, per the ruling on the card (issuecomment-5729189166, batch #158 item 2, letter 1, maintainer 「同意」 2026-09-18T11:14Z).

The Zone-2 measurement, and the branch it selected

The ruling decided both branches in advance and made the route turn on one measurement: does the get_record / loop projection the flow iterates carry computed formula fields?

Measured answer: YES → letter 1 executes. Driven, not inferred: a real kernel, real ObjectQL over a real in-process sqlite-wasm driver, the app's own Task object, read the way the flow's get_record step reads.

The single condition that decides it is the projection. ObjectQL.find runs planFormulaProjection(schema, ast.fields) (packages/objectql/src/engine.ts:1050), which evaluates every formula field on the schema when fields is absent and only the named ones when it is present; applyFormulaPlan then hydrates the rows before find returns (engine.ts:10051). examples/app-todo/src/flows/task.flow.ts declares no fields on get_overdue_tasks, so the rows handed to the loop carry the computed value.

What would have made the answer the other way: a fields list on that get_record step that did not name days_overdue. That is why the first test in the new suite asserts the absence of fields off the app's own flow metadata rather than trusting it — adding one later is exactly the edit that would blank the count again, silently.

Semantics, as ruled

Integer, whole days between due_date and now, 0 when not overdue and 0 when due_date is empty. No working-day calendar and no timezone option — "an example demonstrates the capability, not a scheduling product".

Spelling deviates from the feasibility read in the ruling, semantics do not. The ruling's own text records due_date less-than now() with int((now() - due_date) / duration('24h')) as the director's feasibility argument, explicitly untested. Verified against the actual formula surface in this tree and adopted the registered stdlib pair instead:

record.due_date == null || daysBetween(record.due_date, today()) less-than 0
  ? 0
  : daysBetween(record.due_date, today())
  • daysBetween(a, b) is a registered stdlib function returning int (packages/formula/src/stdlib.ts:311), and today() is the platform's calendar-day function (calendarDayUtc, UTC by default). The pair IS the "UTC whole days" spelling, with no hand-rolled millisecond arithmetic — the same shape examples/app-crm already uses for days_to_close.
  • returnType: 'number' carries the ruled "value type integer": the spec enum is number | text | boolean | date (packages/spec/src/data/field.zod.ts:1577), so number is what "integer" maps to on the real surface. Stated rather than silently dropped.

Why a formula here does not contradict the paragraph above it in the same file

task.object.ts carries a long measured note explaining why is_completed / is_overdue are NOT formulas: a formula field is virtual, so a filter naming one matches nothing. That reasoning is about filters, and it still holds. days_overdue has no filter reading it: its one consumer reads the value off a row get_record already fetched. The field's comment says so and forbids adding such a filter.

Acceptance (the ruling's two legs)

Leg 1 — the number reaches the consumer. The ruling offers two pin sites: the flow's notify step output, or the record projection the loop iterates. This PR pins the second, and the reason is in the acceptance notes below. examples/app-todo/test/overdue-escalation-days-overdue.test.ts asserts that every {currentTask.DOT_TOKEN} in the app's real notify body names a key the projected row carries and renders non-blank, and that the value is the real span (5 days overdue reads 5).

Leg 2 — objectstack validate reports no template-path warning for this flow. Measured both ways, by ablating the field and re-running:

state objectstack validate on examples/app-todo
field ablated (equals origin/main) flow "overdue_escalation" node "notify": template references '{currentTask.days_overdue}', but 'days_overdue' is not a field on object 'todo_task' — it resolves to an empty string at runtime (silently).
this PR warning absent · Validation passed · exit 0

Reverse verification

One-off, run from the committed fix and restored; no permanent artifact.

  • Mutation landed on disk, proven by the tool rather than by an exit code: node scripts/ablation-replace.mjs --file examples/app-todo/src/objects/task.object.ts --anchor ... --delete reported anchor 1 -> 0, blob bae175811d2b -> 3bccf64d25ce.
  • Under ablation the suite goes red in the right place: 2 of 3 tests fail, the first with notify body names {currentTask.days_overdue}: expected ... to have property "days_overdue" — the card's defect, verbatim. The third test (the projection precondition) stays green, correctly: it is about fields, not about the field.
  • Restore verified by state, not by exit code: blob == HEAD (bae175811d2b) and git diff HEAD empty.
  • No dist preflight leg: examples/app-todo builds no dist (its main is objectstack.config.ts) and the suite imports ../src/objects/task.object.js directly, so the mutation's only path to the run is the source file the tool hashed.

Tests and gates

Measured on 255c04af6 (the branch head this PR opens with).

  • pnpm --filter @objectstack/example-todo test :: exit 0 — 233 passed (233), 6 files. Three of those were red at first and are fixed here: translation-completeness.test.ts requires a label in all three locales for every declared field, so the new field carries Days Overdue / 逾期天数 / 超過日数.
  • pnpm --filter @objectstack/example-todo typecheck :: exit 0.
  • pnpm --filter '@objectstack/example-todo^...' build :: exit 0 (dependency closure).
  • Derived for the actual diff, not recalled: node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack → 37 families. All 37 run, exit code captured before any pipe; reconciled with --ran: 37 derived, 36 run, 1 NOT-MEASURED, 0 UNRUN.
    • 36 exit 0.
    • 1 NOT MEASURED: pnpm check:dual-build-cjs-loads :: exit 3 — PREREQUISITE NOT MET — this gate reads built output, and some package has no dist/. Not a pass and not a failure; it needs a full workspace build this container did not run.
  • npx eslint . --no-inline-config --format json :: exit 0 — not narrowed: the whole universe eslint's own config selects was linted, 6906 files, 0 errors, 0 warnings. Type-aware linting is not enabled in eslint.config.mjs (no parserOptions.project), so nothing in this diff could move a verdict on a file it does not touch.

Changeset: measured skip-changeset

examples/app-todo/package.json declares "private": true and no files array, and no published package's files[] ships anything from examples/. The diff therefore publishes nothing from any released package. Requesting the skip-changeset label — this seat's dispatch budget carries no label write.

Acceptance notes

A defect measured on the way through, NOT fixed here, and it is the reason leg 1 pins the projection rather than the notify step output.

overdue_escalation's loop node declares no config.body. That is the legacy flat-graph form (packages/services/service-automation/src/builtin/loop-node.ts:71): the node sets $loopItems / $loopIndex and returns without ever binding iteratorVariable. update_priority and notify_owner sit on ordinary out-edges, which that node's own docblock calls "the after-loop continuation" — so they run once, after the loop, with currentTask unbound.

Observed by running the app's real flow through the real engine:

get_overdue_tasks -> success, selected: 1
loop_overdue      -> success
update_priority   -> FAILURE: "update_record: refusing to run - 1 filter
                     condition(s) resolved to nothing and were dropped from
                     the query: `{currentTask.id}` (at id)."

⇒ the run dies one node before notify_owner, so today no escalation notice is sent at all — the card's described symptom (a notice with a blank where the count belongs) is not what the runtime does. Note this is not specific to days_overdue: {currentTask.subject}, {currentTask.due_date}, {currentTask.owner} and {currentTask.id} are all unbound by the same mechanism, and it predates and outlives this card. task_reminder, two declarations above in the same file, has the identical shape.

Left for the triage seat as a separate class-(a) card rather than folded in: different mechanism (flow-graph structure, not a missing field), different repair (move the two nodes into a config.body region, which per flow-loop-body-uncontained also needs a per-iteration try_catch — the worked form is examples/app-showcase/src/automation/flows/index.ts:908), and it touches both flows in the file. Dedupe words: loop body, iteratorVariable, legacy flat-graph loop, overdue_escalation, currentTask unbound.

Also noted, not filed: pnpm --filter PKG build --concurrency=2 forwards --concurrency=2 into the receiving package script, and packages/cli's build script ends in fi, so the appended token makes sh fail with Syntax error: word unexpected and the closure build exits 2. Observed once here; --workspace-concurrency=2 before --filter is the working spelling. Carrier: the next agent that copies the --concurrency form from a dispatch order. This is a tooling-usage trap rather than a repo defect, so it is noted, not filed.

Files changed (5)

  • examples/app-todo/src/objects/task.object.ts — the field
  • examples/app-todo/src/translations/{en,zh-CN,ja-JP}.ts — its label in all three locales
  • examples/app-todo/test/overdue-escalation-days-overdue.test.ts — new, the acceptance pin

⛔ Draft on purpose: not flipped to ready and not enqueued.


Generated by Claude Code

… escalation notice renders its day count

The overdue escalation notify body interpolates {currentTask.days_overdue}
and todo_task declared no such field, so the count rendered blank. Add it as
a formula: whole days past due_date, 0 when not overdue and 0 when due_date
is empty, via the registered daysBetween/today stdlib pair.

Claude-Session: https://claude.ai/code/session_01AhQASwqJr2Z7XfGWUdvnbF
Co-authored-by: Claude <noreply@anthropic.com>
check:i18n-coverage counted the field's description as two new untranslated
declared strings (106 -> 108): the translation key is `help`, and `en` is the
source locale, so only zh-CN and ja-JP were missing it.

Claude-Session: https://claude.ai/code/session_01AhQASwqJr2Z7XfGWUdvnbF
Co-authored-by: Claude <noreply@anthropic.com>
@huangyiirene
huangyiirene marked this pull request as ready for review September 19, 2026 16:16
@huangyiirene
huangyiirene added this pull request to the merge queue Sep 19, 2026
Merged via the queue into main with commit 10a052c Sep 19, 2026
35 checks passed
@huangyiirene
huangyiirene deleted the claude/issue-18584-days-overdue-formula-field branch September 19, 2026 16:42
akarma-synetal pushed a commit to akarma-synetal/framework that referenced this pull request Sep 28, 2026
…rentTask` binds and the escalation notice is sent (objectstack-ai#19262)

Fixes objectstack-ai#19206

`Clause-②: no`

## What was wrong

Both `loop` nodes in `examples/app-todo/src/flows/task.flow.ts` declared
`collection` + `iteratorVariable` and **no `config.body`**. That is the
**legacy flat-graph** form:
`packages/services/service-automation/src/builtin/loop-node.ts` opens
with `if (raw.body == null)`, sets `$loopItems` / `$loopIndex` and
returns **without binding `iteratorVariable`**. The per-item steps were
wired as ordinary nodes *after* the container, so every
`{currentTask.…}` token in them resolved to nothing.

Measured on a real engine in this PR's control test (`CONTROL: the
pre-fix body-less shape still dies at update_priority`):

```
update_record: refusing to run — 1 filter condition(s) resolved to nothing
and were dropped from the query: `{currentTask.id}` (at id).
```

`notify_owner` sits one node **behind** that refusal, so **no escalation
notice was sent at all** — and the control asserts that too (`emits` has
length 0). `task_reminder` had the identical shape.

## The repair — established from the schema and the engine

The authority is `LoopConfigSchema` / `FlowRegionSchema` in
`packages/spec/src/automation/control-flow.zod.ts` (ADR-0031
representation **(B)**, nested sub-structure) plus the executor's
structured branch:

- `config.body` is a `FlowRegionSchema`: `{ nodes: min 1, edges: default
[] }`, **single-entry / single-exit / acyclic** (`analyzeRegion`),
rejected at `registerFlow()` via `validateControlFlow` when it is not.
- The executor binds `iteratorVariable` in the **enclosing** scope per
item and runs the region through `engine.runRegion`; the loop node's
**ordinary out-edge is the after-loop continuation**, which is why `e3`
now goes `loop → end`.

Each body carries one `try_catch` (`flow-loop-body-uncontained`, the
shape the lint rule's own hint prescribes, and the form
`examples/app-showcase` already demonstrates), with the minimal handler
— one bare `assignment` node. On `overdue_escalation` **one**
`try_catch` wraps **both** per-item steps rather than one each: the
notice announces the escalation the update performs, so a row whose
update was refused must not be told its priority was raised.
`maxIterations: 200` states, on the iterating side, the same bound the
`get_record` step's `limit: 200` already imposes.

## What the notice actually renders — the reading this card unblocks

With the loop body executing, the escalation notice is sent, and
(composed with the `days_overdue` formula that landed in objectstack-ai#19205 /
objectstack-ai#18584) it interpolates. Read off the captured `messaging.emit()`
payload in a real run:

```
title: URGENT: task overdue — Alpha
body:  Due 2026-09-16, 4 day(s) overdue.
```

Three seeded rows render three distinct notices with their own owner,
subject, due date and day count — no leaked binding, no blank hole.

## Tests

`examples/app-todo/test/loop-body-iteration.test.ts` — drives the
**real** flows on a real `AutomationEngine` over a real sqlite-wasm
database holding the app's real `todo_task`. The only double is the
`messaging` service, and it is a **capture**, not a simulation:
capturing `emit()` is how the rendered title/body becomes readable at
all.

1. ESCALATION — run succeeds, the seeded row's `priority` is `urgent`
(so the body's first node matched the right row), exactly one notice,
and its rendered body carries the real day count and no unresolved
brace.
2. EVERY item is processed, each with its own values (a leaked binding
would show as three identical notices).
3. CONTAINMENT — one row with an unresolvable recipient fails inside the
body's `try_catch` and the sweep still reaches the rows after it.
4. REMINDER — the second loop in the file binds its iterator too.
5. CONTROL — the pre-fix body-less shape, rebuilt from the real flow,
still dies at `update_priority` and notifies nobody.

`test/overdue-escalation-days-overdue.test.ts` (the objectstack-ai#18584 pin) keeps
pinning: its `node()` helper now walks the ADR-0031 region slots,
because the nodes it inspects moved into the loop body. The question it
asks is about those nodes' **config**, which nesting does not change.

## Evidence

- `pnpm --filter @objectstack/example-todo exec vitest run` — **exit
0**, 7 files / 238 tests passed.
- `pnpm --filter @objectstack/example-todo typecheck` — the package's
own script is `tsc --noEmit` (read from its `package.json`, one leg) —
**exit 0**.
- `pnpm --filter '@objectstack/example-todo^...' build` — **exit 0**.
- Gate families derived from the real change set with `node
scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack
--commands`: **37 derived, 37 run, 0 NOT-MEASURED, 0 UNRUN** (`--ran`
reconciliation with exit codes recorded before any pipe).
`check:dual-build-cjs-loads` first answered **exit 3 = PREREQUISITE NOT
MET = not measured**; after the missing `dist/` was present it was
re-run and answered **exit 0**.
- `pnpm lint` (repo-wide `eslint . --no-inline-config`, the whole
population, not a narrowed run) — **exit 0** at `c6ca194c2`.

## Changeset

`skip-changeset`: `examples/app-todo/package.json` declares `"private":
true` and the diff touches nothing else, so this publishes nothing from
any released package.

## Scope

`examples/app-todo/` only. No engine change was needed — and none was
made: the container the schema already declares is what binds the
iterator. `packages/spec/**` and `content/docs/releases/**` are
untouched.

## Acceptance notes

- `noted, not filed:` the two scheduled sweeps read date macros
(`{tomorrow}`, `{3_days_ago}`) that `interpolateFilter` deliberately
passes through verbatim for the data layer to resolve. Working as
designed here; recorded only because the same brace syntax means
something different one line away in the same config. Not a defect, not
filed.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01AhQASwqJr2Z7XfGWUdvnbF)_

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m skip-changeset PR has no user-facing published change; bypasses the changeset gate tests

Projects

None yet

2 participants